package 力扣;

/**
 输入：matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,50]], target = 3
 输出：true
 输入：matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,50]], target = 13
 输出：false
 示例 3：

 输入：matrix = [], target = 0
 输出：false

 */
public class _74搜索二维矩阵 {
    public boolean searchMatrix(int[][] matrix, int target) {
        // 剑指offer 第一题
        int m = matrix.length;
        int n = matrix[0].length;
        int i =0;
        int j =n-1;
        while( i <= m-1  && j>= 0 ){
            int temp = matrix[i][j];
            // 右上角开始
            if( temp ==target){
                return true;
            }else if( temp > target ){
                j--;
            } else{
                i++;
            }
        }
        return false;
    }
}
